package com.situ.team5.kzq.recruit.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.team5.kzq.recruit.dao.SalaryGrantDetailsDAO;
import com.situ.team5.kzq.recruit.service.EngageResumeService;
import com.situ.team5.kzq.recruit.service.SalaryGrantDetailsService;
import com.situ.team5.pojo.*;
import com.situ.team5.util.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;
import java.util.Map;
//设置  @RequestMapping("position_register")名字为页面名字，方法名相同；
//职位发表登记控制层
@Controller
public class SalaryGrantDetailsController extends BaseController {
    //职位发布登记

    @Autowired
    SalaryGrantDetailsService dao;
    @Autowired
    EngageResumeService endao;

    @RequestMapping("position_register")
    public String position_register(Map map){
        //一级机构全查
        List<ConfigFileFirstKind> configFileFirstKinds = dao.file_first_kindSelect();
        //职位分类表全查
        List<ConfigMajorKind> configMajorKinds = dao.config_major_kindSelect();
        map.put("configFileFirstKinds",configFileFirstKinds);
        map.put("configMajorKinds", configMajorKinds);
        return "/page/recruit/position/position_register.html";
    }

    //查找与一级机构有关的二级机构
    @RequestMapping("yijierjiajax")
    @ResponseBody
    public List<ConfigFileSecondKind> position_registerAjax( int id) {
        //查找与一级机构有关的二级机构
        List<ConfigFileSecondKind> configFileSecondKinds = dao.file_second_kindSelectOne(id);
        System.out.println(configFileSecondKinds);
        return  configFileSecondKinds;

    }
    @RequestMapping("erjisanjiajax")
    @ResponseBody
    public List<ConfigFileThirdKind> ConfigMajorKindAjax2( int id) {
        //查找与二级机构有关的三级机构数据
        List<ConfigFileThirdKind> ThirdKinds = dao.file_third_kindSelectOne(id);
        System.out.println(ThirdKinds);
        return  ThirdKinds;

    }
    //职位设置表的二级联动
    @RequestMapping("zwflajax")
    @ResponseBody
    public List<ConfigMajor> position_registerAjax2( int id) {
        //通过职位分类表的id查询职位设置表的数据
        List<ConfigMajor>  configMajor= dao.config_majorSelectOne(id);
        System.out.println(configMajor);
        return  configMajor;
    }


    // 职位发布添加
    @RequestMapping("position_change_update_html_insert")
    public String  position_change_update_html_insert(EngageMajorRelease er){
        dao.EngageMajorReleaseInsert(er);
return "redirect:position_change_update";

    }

    //职位发布变更
    @RequestMapping("position_change_update")
    //engage_major_release表
    public String position_change_update(Map map,
                                         @RequestParam(defaultValue = "1",required = false) Integer startPage,
                                         @RequestParam(defaultValue = "2",required = false) Integer PageSize ){
        //对职位变更表的全查
        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        List<Map> engageMajorReleases = dao.engage_major_releaseSelectAll();
        PageInfo pageInfo=new PageInfo(engageMajorReleases, 2); //保存分页信息

        map.put("pageInfo", pageInfo);
        map.put("engageMajorReleases", engageMajorReleases);
        return "/page/recruit/position/position_change_update.html";
    }
    //修改  position_release_change.html
    //通过id查询
    @RequestMapping("position_release_change")
    public String position_release_change(Map map,Integer id){
        //一级机构全查
        List<ConfigFileFirstKind> configFileFirstKinds = dao.file_first_kindSelect();
        //职位分类表全查
        List<ConfigMajorKind> configMajorKinds = dao.config_major_kindSelect();
        //通过id查询
        Map engageMajorRelease = dao.EngageMajorReleaseupdate(id);
        map.put("en", engageMajorRelease);
        map.put("configFileFirstKinds",configFileFirstKinds);
        map.put("configMajorKinds", configMajorKinds);

        return "/page/recruit/position/position_release_change.html";

    }
    //真的修改
    @RequestMapping("position_release_change_update2")
    public String position_release_changeupdate2(EngageMajorRelease e){
        //通过id查询
        System.out.println(e.getMre_id()+"法法");
       dao.EngageMajorReleaseupdate2(e);

        return "redirect:position_change_update";

    }

    //职位发布查询
    @RequestMapping("position_release_search")
    public String position_release_search(Map map,
                                          @RequestParam(defaultValue = "1",required = false) Integer startPage,
                                          @RequestParam(defaultValue = "2",required = false) Integer PageSize){
        //对职位变更表的全查
        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        List<Map> engageMajorReleases = dao.engage_major_releaseSelectAll();
        PageInfo pageInfo=new PageInfo(engageMajorReleases, 2); //保存分页信息

        map.put("pageInfo", pageInfo);
        map.put("engageMajorReleases", engageMajorReleases);
        return "/page/recruit/position/position_release_search.html";
    }
    //职位发布查询页面联动数据查询
    //申请该职位
    @RequestMapping("position_release_details")
    public String position_release_details(Map map, int id){
        //通过id查询
        Map engageMajorRelease = dao.EngageMajorReleaseupdate(id);
        System.out.println("职位编号"+engageMajorRelease);
        map.put("en", engageMajorRelease);


        return "/page/recruit/position/position_release_details.html";
    }
    //职位发布查询的确认申请功能
    @RequestMapping("resume_register_sq")
    public String  resume_register_sq(int id,Map map){
        List<ConfigMajorKind> configMajorKinds = dao.config_major_kindSelect();
        //config_public_char国籍查询
        //集合下标是0 开始的
        String[] bb={"国籍","民族","宗教信仰","政治面貌","学历","教育年限","专业","特长","爱好"};
        for(int i=0;i<bb.length;i++){
            List<ConfigPublicChar> configPublicChars = endao.config_public_charSelectGJ(bb[i]);
            map.put("configPublicChars"+i, configPublicChars);
        }
        Map engageMajorRelease = dao.EngageMajorReleaseupdate(id);
        map.put("configMajorKinds", configMajorKinds);
        map.put("en",engageMajorRelease);
return "/page/recruit/resume/resume-register.html";
    }
    //点击确认申请，填写简历表
    @RequestMapping("register_insert1")
    public String register_insert1(EngageResume e ){
        endao.engage_resumeInsert(e);
        return "redirect:position_release_search";

    }

    //删除
    @RequestMapping("position_change_update_delete")
public String  position_change_update_delete(int id){
    dao.engage_major_releaseDelete(id);
        return "redirect:position_change_update";
    }

}
